<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>51问医生</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <script src="{{url('/js/jquery.min.js')}}" type="text/javascript"></script>

    <!-- Plupload上传类 -->
    <script src="{{ url('vendor/plupload-2.1.2/plupload.full.min.js') }}"></script>
    <script src="{{ url('vendor/plupload-2.1.2/i18n/zh_CN.js') }}"></script>

    <!-- Noty 提示框的js集成 -->
    <script src="{{ url('vendor/noty-2.2.9/packaged/jquery.noty.packaged.js') }}"></script>
    <script src="{{ url('vendor/noty-2.2.9/themes/bootstrap.js') }}"></script>
    <script src="{{ url('vendor/noty-2.2.9/options.js') }}"></script>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style>
        html, body
        {
            padding: 0;
            margin: 0;
            height: 100%;
            overflow:hidden;
        }
        .btn-submit button {
            margin-top: .746666666666667rem;
        }
        .btn-submit button {
            margin: .533333333333333rem 3.733333333333333% .32rem;
            width: 91.46666666666667%;
            font-weight: 400;
        }
        .ax-bareBtn button, .ax-subBtn button {
            width: 67.73333333333333%;
            border-radius: .026666666666667rem;
            background: #fc8f0f;
            border: 0;
            height: 1.173333333333333rem;
            line-height: 1.173333333333333rem;
            text-align: center;
            color: #fff;
            font-size: .426666666666667rem;
            font-weight: bolder;
            display: inline-block;
            outline: 0;
        }

        .content{
            padding-top: 7px;
            padding-left: 20px;
            padding-right: 20px;
        }
        .tips{
            text-align: center;
            font-size: 16px;
            padding: 20px;
        }
        .time-area{
            margin-left: 45%;
        }
        .time-area span{
            font-size: 15px;
            font-weight: bold;
        }
        .time-area .second-time{
            margin-left: 45%;
        }

        .week{
            width: 30%;
            text-align: center;

        }
        .btn{
            padding: 5px;
            width: 70px;
            border: 1px solid #ffffff;
            color: #ffffff;
            background-color: #cac3c3;
        }
        .cur{
            background-color: #fc8f0f;
        }
        .table-bordered td{
            text-align: center;
        }
        .set_value{
            margin-top: 5px;
        }
        .set_value input{
            width: 70%;
            border: 1px solid #76757c;
        }
    </style>

</head>
<body>
<div class="content">
    <div class="tips">
        <span>设置近期可预约门诊时间</span>
    </div>
    <div class="seting">
        <div class="time-area">
            <span class="first-time">上午</span>
            <span class="second-time">下午</span>
        </div>
        <table class="table table-bordered">
            <tr>
                <td class="week">今天</td>
                <td><button class="btn @if($date_one && $date_one->am == 1)cur @endif" data-id="one" data-time="am" is-select="@if($date_one){{$date_one->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_one && $date_one->pm == 1)cur @endif" data-id="one" data-time="pm" is-select="@if($date_one){{$date_one->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_one" value="{{date('Y-m-d',time())}}">
                <input type="hidden" id="work_one" value="@if($date_one && $date_one->am == 1)am @elseif($date_one && $date_one->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+1 days'))}}</td>
                <td><button class="btn @if($date_two && $date_two->am == 1)cur @endif" data-id="two" data-time="am" is-select="@if($date_two){{$date_two->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_two && $date_two->pm == 1)cur @endif" data-id="two" data-time="pm" is-select="@if($date_two){{$date_two->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_two" value="{{date('Y-m-d',strtotime('+1 days'))}}">
                <input type="hidden" id="work_two" value="@if($date_two && $date_two->am == 1)am @elseif($date_two && $date_two->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+2 days'))}}</td>
                <td><button class="btn @if($date_three && $date_three->am == 1)cur @endif" data-id="three" data-time="am" is-select="@if($date_three){{$date_three->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_three && $date_three->pm == 1)cur @endif" data-id="three" data-time="pm" is-select="@if($date_three){{$date_three->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_three" value="{{date('Y-m-d',strtotime('+2 days'))}}">
                <input type="hidden" id="work_three" value="@if($date_three && $date_three->am == 1)am @elseif($date_three && $date_three->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+3 days'))}}</td>
                <td><button class="btn @if($date_four && $date_four->am == 1)cur @endif" data-id="four" data-time="am" is-select="@if($date_four){{$date_four->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_four && $date_four->pm == 1)cur @endif" data-id="four" data-time="pm" is-select="@if($date_four){{$date_four->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_four" value="{{date('Y-m-d',strtotime('+3 days'))}}">
                <input type="hidden" id="work_four" value="@if($date_four && $date_four->am == 1)am @elseif($date_four && $date_four->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+4 days'))}}</td>
                <td><button class="btn @if($date_fire && $date_fire->am == 1)cur @endif" data-id="fire" data-time="am" is-select="@if($date_fire){{$date_fire->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_fire && $date_fire->pm == 1)cur @endif" data-id="fire" data-time="pm" is-select="@if($date_fire){{$date_fire->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_fire" value="{{date('Y-m-d',strtotime('+4 days'))}}">
                <input type="hidden" id="work_fire" value="@if($date_fire && $date_fire->am == 1)am @elseif($date_fire && $date_fire->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+5 days'))}}</td>
                <td><button class="btn @if($date_six && $date_six->am == 1)cur @endif" data-id="six" data-time="am" is-select="@if($date_six){{$date_six->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_six && $date_six->pm == 1)cur @endif" data-id="six" data-time="pm" is-select="@if($date_six){{$date_six->am}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_six" value="{{date('Y-m-d',strtotime('+5 days'))}}">
                <input type="hidden" id="work_six" value="@if($date_six && $date_six->am == 1)am @elseif($date_six && $date_six->am == 0)pm @endif">
            </tr>
            <tr>
                <td class="week">{{\App\Services\Tools::getWeek(strtotime('+6 days'))}}</td>
                <td><button class="btn @if($date_seven && $date_seven->am == 1)cur @endif" data-id="seven" data-time="am" is-select="@if($date_seven){{$date_seven->am}}@else 0 @endif">出诊</button></td>
                <td><button class="btn @if($date_seven && $date_seven->pm == 1)cur @endif" data-id="seven" data-time="pm" is-select="@if($date_seven){{$date_seven->pm}}@else 0 @endif">出诊</button></td>
                <input type="hidden" id="date_seven" value="{{date('Y-m-d',strtotime('+6 days'))}}">
                <input type="hidden" id="work_seven" value="@if($date_seven && $date_seven->am == 1)am @elseif($date_seven && $date_seven->am == 0)pm @endif">
            </tr>
        </table>
    </div>
    <div>
        <div class="set_value">
            <span>预约费用</span>
            <input type="text" id="amount" value="@if($doctor){{$doctor->fee}}@endif" placeholder="请输入预约费用" />
        </div>
        <div class="set_value">
            <span>限制人数</span>
            <input type="text" id="max_num" value="@if($doctor){{$doctor->appoint_num}}@endif" placeholder="请输入每日最大预约人数" />
        </div>
    </div>
    <div class="btn-submit  ax-bareBtn" style="height: 35px;margin-top: 5px">
        <button type="submit" id="btn_send" style="width: 92%;height: 100%;font-size: 16px">
            <i class="ax-pay-loading"></i>提交</button>
    </div>
</div>
<script>
    $(function(){
        $(document).on('click','.btn',function(){
            var dataId = $(this).attr('data-id');
            var dayTime = $('#date_'+dataId).val();
            var dataTime = $(this).attr('data-time');
            var isSelect = $(this).attr('is-select');
            var am='',pm='';
            if(parseInt(isSelect) == 1){
                if($.trim(dataTime) == 'am'){
                    am = 0;
                    setWorkTime(dayTime,am,pm);
                }else if($.trim(dataTime) == 'pm'){
                    pm = 0;
                    setWorkTime(dayTime,am,pm);
                }
                $(this).removeClass('cur');
                $(this).attr('is-select','0');
            }else{
                if($.trim(dataTime) == 'am'){
                    am = 1;
                    setWorkTime(dayTime,am,pm);
                }else if($.trim(dataTime) == 'pm'){
                    pm = 1;
                    setWorkTime(dayTime,am,pm);
                }
                $(this).addClass('cur');
                $(this).attr('is-select','1');
            }

//            var workTime = $.trim($('#work_'+dataId).val());
//
//            if(dataTime == workTime){
//                $(this).removeClass('cur');
//                $('#work_'+dataId).val('');
//                setWorkTime(dayTime,0,0);
//            }else{
//                if(dataTime == "am"){
//                    setWorkTime(dayTime,1,0);
//                    $(".btn[data-id="+dataId+"][data-time='pm']").removeClass('cur');
//                    $('#work_'+dataId).val('am');
//                }else{
//                    $(".btn[data-id="+dataId+"][data-time='am']").removeClass('cur');
//                    $('#work_'+dataId).val('pm');
//                    setWorkTime(dayTime,0,1);
//                }
//                $(".btn[data-id="+dataId+"][data-time='am']").removeClass('cur');
//                $('#work_'+dataId).val('pm');
//                setWorkTime(dayTime,0,1);
//            }
        });

        function setWorkTime(day,am,pm){
            $.ajax({
                url:'{{route('Api.Doctor.setWorkTime')}}',
                type:'post',
                dataType:'json',
                data:{
                    day:day,
                    am:am,
                    pm:pm
                },
                success:function(obj){
                    if(obj.level == 'success'){
                        console.log(obj.message);
                    }
                },
                error:function(obj){
                    console.log(log);
                }
            });
        }

        function isPirce(s){
            s =  $.trim(s);
            var p =/^[1-9](\d+(\.\d{1,2})?)?$/;
            var p1=/^[0-9](\.\d{1,2})?$/;
            return p.test(s) || p1.test(s);
        }

        $(document).on('click','#btn_send',function(){
            var amount = $('#amount').val();
            var max_num = $('#max_num').val();
            if(!isPirce(amount)){
                noty({type:'error',text:'金额必须为数字,保留小数点后2位',timeout:600});
                return ;
            }

            if(amount.length == 0 || max_num.length == 0){
                noty({type:'error',text:'金额和限制人数不能为空',timeout:600});
                return ;
            }

            if(isNaN(max_num) && parseInt(max_num)>0){
                noty({type:'error',text:'人数必须为整数数字',timeout:600});
                return ;
            }

            $.ajax({
                url:'{{route('Api.Doctor.setWorkLimit')}}',
                type:'post',
                dataType:'json',
                data:{
                    num:max_num,
                    amount:amount
                },
                success:function(obj){
                    if(obj.level == 'success'){
                        noty({text:obj.message,type:obj.level,timeout:600,
                            callback:{
                                afterClose:function(){
                                    window.location.href="{{route('M.Doctor.setFace')}}";
                                }
                            }
                        });
                    }
                },
                error:function(obj){
                    var dataJson = obj.responseJSON;
                    noty({type:dataJson.level,text:dataJson.message,timeout:600});
                }
            });
        });
    });
</script>
</body>
</html>